import React, { useRef } from 'react';
import FunctionSelector from '@/pages/Setting/Privilege/components/FunctionSelector';
import { Form, Spin } from 'antd';

const FunctionPermission = ({ form, loading, isShow }) => {
    const { getFieldDecorator } = form;
    const functionSelectorRef = useRef();

    return (
        <Spin spinning={loading}>
            <Form>
                <Form.Item>
                    {getFieldDecorator('authorityList', {
                        rules: [
                            {
                                validator: (rule, value, callback) => {
                                    if (functionSelectorRef.current?.hasCheckedValue() === false) {
                                        callback('请选择权限');
                                    } else {
                                        callback();
                                    }
                                }
                            }
                        ]
                    })(<FunctionSelector ref={functionSelectorRef} isShow={isShow} />)}
                </Form.Item>
            </Form>
        </Spin>
    );
};

export default Form.create()(FunctionPermission);
